﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public enum E_SliderMode
{ 
    Horizontal,
    Vertical
}

public class GUISlider : CustomGUIController
{
    public UnityAction<float> changeValueEvent;

    public E_SliderMode sliderMode = E_SliderMode.Horizontal;

    public float maxValue = 1.0f;
    public float minValue = 0.0f;

    //滑动块的样式
    public GUIStyle thumbStyle;

    private float curValue = 0.5f;
    private float preValue = 0.5f;



    protected override void DrawStyleOn()
    {
        switch (sliderMode)
        {
            case E_SliderMode.Horizontal:
                curValue = GUI.HorizontalSlider(pos.Pos, curValue, minValue, maxValue, style, thumbStyle);
                break;
            case E_SliderMode.Vertical:
                curValue = GUI.VerticalSlider(pos.Pos, curValue, minValue, maxValue, style, thumbStyle);
                break;
        }

        if (preValue != curValue)
        {
            changeValueEvent?.Invoke(curValue);
            preValue = curValue;
        }
    }

    protected override void DrawStyleOff()
    {
        switch (sliderMode)
        {
            case E_SliderMode.Horizontal:
                curValue = GUI.HorizontalSlider(pos.Pos, curValue, minValue, maxValue);
                break;
            case E_SliderMode.Vertical:
                curValue = GUI.VerticalSlider(pos.Pos, curValue, minValue, maxValue);
                break;
        }

        if (preValue != curValue)
        {
            changeValueEvent?.Invoke(curValue);
            preValue = curValue;
        }
    }

}
